class Animal {
    public String name = "lisi";
    public int age;

    public Animal(int age) {

        this.age = age;
    }

    public void eat() {
        System.out.println("你猜是谁");
    }
}

class Dog1 extends Animal {

    public String name = "zhangsan";
    public Dog1( int age) {
        super( age);

    }

    public void eat() {
        System.out.println(name + "吃骨头");
        System.out.println(name);
    }
}

class Cat1 extends Animal {

    public Cat1( int age) {

        super ( age);
    }

    public void eat() {
        System.out.println(name + "吃鱼");
    }
}


public class Demo1 {


    public static void shuichi(Animal a ) {

        a.eat();
    }

    public static void main1(String[] args) {

        Animal a = new Animal( 3233);
        Dog1 d = new Dog1(2);
        Cat1 c = new Cat1(4);
        shuichi(d);
        shuichi(c);
        shuichi(a);

        Dog1 d1 = new Dog1( 3);
    }

    public static void main2(String[] args) {

        Animal a1 = new Dog1( 3);
        Animal a2 = new Cat1( 5);


        shuichi(a1);
        shuichi(a2);

        shuichi(isWhat("狗"));
        shuichi(isWhat("猫"));


    }

    public static Animal isWhat(String s) {

        if (s.equals("狗")) {
            return new Dog1( 1);
        } else if (s.equals("猫")) {
            return new Cat1( 1);
        } else {
            return null;
        }
    }

    public static void main(String[] args) {

        Dog1 dog1 = new Dog1(1 );
        Cat1 cat1 = new Cat1(1);

        Animal animal = dog1;
        System.out.println(animal.name);
        animal.eat();
        animal = cat1;
        animal.eat();

        if(animal instanceof Dog1){

            dog1 = (Dog1)animal;

            dog1.eat();

        }
        if(animal instanceof Cat1) {
            cat1 = (Cat1) animal;
            cat1.eat();
        }

    }
}
